package com.gdiss.www.config;

import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @author yly
 * @date 2021/2/2 13:59
 *
 * MapperScan:在这里添加扫描包注解后，就可以不用在主方法添加这个注解
 * EnableTransactionManagement:自动开启事务管理
 * Configuration:标志配置类
 */
@MapperScan("com.gdiss.www.mapper")
@EnableTransactionManagement
@Configuration
public class MyBatisPlusConfig {

    /**
     * 注册乐观锁插件
     * @return bean
     */
    @Bean
    public OptimisticLockerInterceptor optimisticLockerInterceptor(){
        return new OptimisticLockerInterceptor();
    }

    /**
     * 注册分页插件
     * @return bean
     */
    @Bean
    public PaginationInterceptor paginationInterceptor(){
        return new PaginationInterceptor();
    }

    /**
     * 注册逻辑删除（3.1.1后不再需要注册）
     * @return bean
     */
    //todo 看后续需要
    /*@Bean
    public ISqlInjector iSqlInjector(){
        return new LogicSqlInjector();
    }*/

    //性能分析插件
    /*@Bean
    @Profile({"dev","test"})//设置dev test 环境开启
    public PerformanceInterceptor performanceInterceptor(){
        PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
        //这里设置为1ms
        performanceInterceptor.setMaxTime(1000);//单位ms 设置sql语句执行最大时间，超过就不执行，停止服务
        performanceInterceptor.setFormat(true);//格式化输出
        return performanceInterceptor;
    }*/
}
